package com.dlb.andorid.presenter;

import com.dlb.andorid.XAPI;
import com.dlb.andorid.XContract;
import com.dlb.andorid.XPresenter;
import com.dlb.andorid.XServerMsg;

import java.util.HashMap;

public class RegPresenter extends XPresenter {

	public final static int REG_TYPE_WX = 1;
	public final static int REG_TYPE_PHONE = 2;


	XContract.IRegView iView;

	public RegPresenter(XContract.IRegView iView) {
		super(iView);
		this.iView = iView;
	}

	public void regByPhone(String phone, String pwd, String code) {
		//{"type":2,"data":{"phone":"","password":"",""code":""}}   手机+密码
		mModel.reg("{\"type\":2,\"data\":{\"phone\":\"" + phone + "\",\"password\":\"" + pwd + "\",\"code\":\"" + code + "\"}}");
	}

	public void findPwd(String code, String phone, String password){
		mModel.findPwd(code, phone, password);
	}



	public void getCode(String phone, int ctype) {
		mModel.getCode(phone, ctype);
	}

	@Override
	public void onDataSuccess(int vocational_id, HashMap<String, Object> exData, Object data) {
		super.onDataSuccess(vocational_id, exData, data);
		switch (vocational_id){
			case XAPI.REG_VOCATIONAL_ID:
				iView.onRegSuccess(((XServerMsg) data).getMsg());
				break;
			case XAPI.GET_CODE_VOCATIONAL_ID:
				iView.getCodeSuccess(((XServerMsg) data).getMsg());
				break;
			case XAPI.GET_PASSWORD_VOCATIONAL_ID:
				iView.getPwdSuccess(((XServerMsg) data).getMsg());
				break;
		}
	}
}
